import {Injectable} from "@angular/core";

import {interfaceUrls} from './serverUrls';	//没有真实数据暂时不需要引入接口
import {Http, Headers} from "@angular/http";

import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/timeout';


@Injectable()
export class servicess {
	  private headers = new Headers({'Content-Type': 'application/json; charset=utf-8'});
	  params={};
	  constructor(public http: Http) {
  };
  	//定义一个出现错误时的回调函数
  	  private handleError(error: any): Promise<any> {
      return Promise.reject(error.message || error);
  }
  	/*  定义一个POST请求*/
  	 postMethod(url: string, param: any): Promise<any> {
      return this.http
      .post(url, JSON.stringify(param), {headers: this.headers})
      .timeout(2000) 	
      .toPromise()
      .then(response => response.json())
      .catch(this.handleError);

 }
  	 
 //home页数据请求
// 	ngAfterViewInit(params:any){
// 		this.postMethod(interfaceUrls.repertoryList,this.params)
// 		 .then((response) => {
//	    console.info(response.json().infoData.items)
//	    this.items = response.json().infoData.items;
//	  })
//	  .catch( err => {
//	    console.log('err');
//	  })
// 	}
 	
 	

	
	
	
	
	
}























